/*
 * @lc app=leetcode id=905 lang=javascript
 *
 * [905] Sort Array By Parity
 *
 * https://leetcode.com/problems/sort-array-by-parity/description/
 *
 * algorithms
 * Easy (72.26%)
 * Total Accepted:    77.4K
 * Total Submissions: 107.2K
 * Testcase Example:  '[3,1,2,4]'
 *
 * Given an array A of non-negative integers, return an array consisting of all
 * the even elements of A, followed by all the odd elements of A.
 * 
 * You may return any answer array that satisfies this condition.
 * 
 * 
 * 
 * 
 * Example 1:
 * 
 * 
 * Input: [3,1,2,4]
 * Output: [2,4,3,1]
 * The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.
 * 
 * 
 * 
 * 
 * Note:
 * 
 * 
 * 1 <= A.length <= 5000
 * 0 <= A[i] <= 5000
 * 
 * 
 * 
 */
/**
 * @param {number[]} A
 * @return {number[]}
 */
let array = [0, 1];
var sortArrayByParity = function (A) {
    let newArray = [];
    for (let i = 1; i < A.length; i++) {
        // console.log(A[i]);
        Number.isInteger(A[i] / 2) ? newArray.unshift(A[i]) : newArray.push(A[i]);
    }
    console.log(newArray);
    return newArray;

    /**
     * 偶数形成list，奇数形成list，最后两个直接相加
     *拿出第一个数放到新list，剩余的数判断奇偶，如果奇数就append到后面，如果是偶数就insert到最开始。
     *以第一个数为基准，然后依次跟下一个数比较，下一个如果是偶数就交换位置。
    */
};
sortArrayByParity(array);

